package com.demo2.todo.model.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;

/**
 * @author evi
 */

public enum TodoStatus {
    @Enumerated(EnumType.STRING)
    pending,
    completed;
    // 反序列化时忽略大小写
    @JsonCreator
    public static TodoStatus fromString(String value) {
        for (TodoStatus status : TodoStatus.values()) {
            if (status.name().equalsIgnoreCase(value)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的状态值: " + value);
    }
}
